package com.example.demo.service.impl;


import com.example.demo.entity.vo.QuartzSosVO;
import com.example.demo.quartz.QuartzManager;
import com.example.demo.service.IQuartzService;
import org.quartz.Job;
import org.springframework.stereotype.Service;

/**
 *   @Author:Sjy
 *   @Date: 2024/4/15-04-15-19:1I
 */
@Service
public class QuartzServiceImpl implements IQuartzService {

    /**
     * 启动或停止业务 返回成功或失败
     * @Author: sjy
     * @param quartzSosVO
     * @return 成功或失败
     * @Date: 2024/4/15 19:15
     */
    @Override
    public boolean startOrStop(QuartzSosVO quartzSosVO) throws ClassNotFoundException {
        if(quartzSosVO.isJobStatus()){
            QuartzManager.addJob(quartzSosVO.getJobName(), (Class<? extends Job>) Class.forName(quartzSosVO.getJobClassName()), quartzSosVO.getCron());
        }else{
            //移除任务
            QuartzManager.removeJob(quartzSosVO.getJobName());
        }
        return true;
    }
}
